package com.cntcdt.api.db.dao;

import java.util.Date;
import java.util.List;

import com.cntcdt.api.db.dao.base.DeviceLostlinkRecordDaoBase;
import com.cntcdt.api.db.model.BuyHistoryModel;
import com.cntcdt.api.db.model.DeviceLostlinkRecordModel;

/**
 * 这是cnt_device_lostlink_record的Dao实现类
 */
public class DeviceLostlinkRecordDao extends DeviceLostlinkRecordDaoBase {
	/**
	 * DeviceLostlinkRecordDao对象
	 */
	private static DeviceLostlinkRecordDao instance = new DeviceLostlinkRecordDao();

	/**
	 * 默认构造方法
	 */
	private DeviceLostlinkRecordDao() {
	}

	/**
	 * 获得对象实例
	 */
	public static DeviceLostlinkRecordDao getInstance() {
		return instance;
	}

	/**
	 * 分页查询某台设备的断线记录
	 * 
	 * @param terminal
	 * @param sortTime
	 * @return
	 */
	public List<DeviceLostlinkRecordModel> findByTerminal(String terminal, int sortTime) {
		sortTime = sortTime * 20;
		String sql = "SELECT * FROM " + TABLE + " WHERE terminal = ? order by lostLinkTime desc limit ?,20";
		Object[] paramObjs = { terminal, sortTime };
		List<DeviceLostlinkRecordModel> modelList = this.queryModelList(sql, paramObjs);
		return modelList;
	}

	/**
	 * 查询单台设备24小时断线次数
	 * 
	 * @param terminals
	 * @return
	 */
	public List<DeviceLostlinkRecordModel> findByTerminal(String terminals) {
		String sql = "select * from " + TABLE + " where lostLinkTime <= ? and lostLinkTime >= ? and terminal in (" + terminals
				+ ")";
		Object[] paramObjs = { new Date(), new Date(System.currentTimeMillis() - 24 * 60 * 60 * 1000) };
		List<DeviceLostlinkRecordModel> modelList = this.queryModelList(sql, paramObjs);
		return modelList;
	}
}
